import React, { Component } from 'react';
import { List } from 'antd-mobile';
import {postData} from '../../../utils/request';
import {getParamsList} from '../../../utils/queryData';
import dkmobileCall from '../../../utils/dkmobileCall';
import httpweb from '../../../utils/httpWeb';
import * as $ from '../../../utils/tool';
import Share from '../../../components/shareComp/js';
import Vconsole from 'vconsole';
import './index.scss';
new Vconsole();

const Item = List.Item;

export default class ButtonCollect extends Component{
  state = {
    query:{
      page: 1,
      pageSize: 9999,
      params:{}
    },
    buttonList: [],
    shareData:{
      picUrl:'https://fxbssdl.kgimg.com/bss/fxvideoimg//11297fdda8320e928cf350d2f494ef06.jpg',
      title:'分享标题',
      linkUrl:window.location.href,
      content:'分享文案'
    },
    shareShow: false,
  }
  getParamsList = () => {
    let {page, pageSize, params} = this.state.query;
    postData ('', {
      query: getParamsList ({page, pageSize, params}),
    }).then (res => {
      let list = res.data.defaultParams.list;
      list = list.map (item => {
        return {
          ...item,
          params: JSON.stringify (item.params, null, 4),
        };
      });
      this.setState ({buttonList: list});
    });
  };
  callup = (props)=>{
    let options = {
      cmd: props.code,
      data: JSON.parse (props.params),
    };
    console.log(options);
    try{
      if ($.boolDk) {
        dkmobileCall(options)
      } else {
        httpweb.nativeCall(options)
      }
    } catch(err){
      console.log(err)
    }
  }
  share = ()=>{
    this.setState({shareShow: true})
  }
  componentDidMount(){
    this.getParamsList();
    let shareData = {
      title:'分享标题',
      desc:'分享文案',
      link:window.location.href,
      image: 'https://fxbssdl.kgimg.com/bss/fxvideoimg//11297fdda8320e928cf350d2f494ef06.jpg',
      
    }
    let imgShareData = {
      image: 'http://s3.fx.kgimg.com/v2/fxroomcover/2de3d4bd4717a3d8e45c90722d6e922e.jpg',
      link: 'http://mfanxing.kugou.com/staticPub/rmobile/shortVideo/views/index.html?pageType=0&fromType=duanku&videoId=72e50881ab914e68b42440d7b6e98d76&sharetime=1544606249641',
      title:'',
      desc: '分享文案',
      type: 2
    }
    let sData = {shareList: ['onShareImage', 'onShareWechat', 'onShareTimeline', 'onShareQQ', 'onShareQzone', 'onShareSina'],
    onShareImage: imgShareData,
    onShareWechat: shareData,
    onShareTimeline: shareData,
    onShareQQ: shareData,
    onShareQzone: shareData, 
    onShareSina: shareData,}
    if ($.boolKg) {
      httpweb.nativeCall({
        cmd: 629,
        data:{
          isShow: true,
          shareData: sData
        }
      })
    }
    
  }
  render(){
    let { buttonList } = this.state;
    return (
      <div className="button-collect">
        <List renderHeader={() => '拉起列表'} className="my-list">
          {
            buttonList.map((item, index)=>(
              <Item key={index} arrow="horizontal" onClick={() => {this.callup(item)}}>{item.description}</Item>
            ))
          }
          <Item arrow="horizontal" onClick={() => {this.share()}}>拉起面板分享</Item>
        </List>
        <Share 
          show={this.state.shareShow}
          shareData={this.state.shareData}
          closeFun={()=>{
            this.setState({shareShow:false})
          }}
        />
      </div>
    )
  }
}